<%@page import="com.bjgov.scoresys.dao.ScoreHistoryDAO"%>
<%@include file="/pub/import.jsp"%>
<%@include file="/pub/header.jsp"%>
<%
    int projectId = RequestUtil.getIntParameter(request,"projectId", 0);
    int treeId = RequestUtil.getIntParameter(request,"treeId", 0);
    Project project = ProjectHandler.getProject(projectId);
    int[] pidarr = new int[]{0,0,0,0};
    if(!StringUtils.isEmpty(project.getBuildUnit())) pidarr[0] = 1;
    if(!StringUtils.isEmpty(project.getConstructUnit())) pidarr[1] = 3;
    if(!StringUtils.isEmpty(project.getSupervisorUnit())) pidarr[2] = 40;
    if(!StringUtils.isEmpty(project.getDesignUnit())) pidarr[3] = 44;
    List<ScoreTree> treeList = ScoreTreeHandler.loadByPIDs(pidarr);
    context.put("DateUtil", new DateUtil());
    context.put("project",project);
    context.put("treeList",treeList);
    
    List<ProjectItems> projectItemsList = ProjectItemsHandler.getByProjectIdTreeId(projectId, treeId);
    Map<Integer,ScoreHistory>  hasScoreItemMap = new HashMap<Integer,ScoreHistory>();
    if(projectItemsList!=null && projectItemsList.size()>0) {
      String projectItemIds = "";
      for(int i=0; i<projectItemsList.size(); i++) {
        projectItemIds += projectItemsList.get(i).getScoreItem().getId();//评分子项ID
        if(i!=projectItemsList.size()-1) projectItemIds += ","; 
      }
      List<ScoreHistory> hasScoreItemList = ScoreHistoryHandler.getByUserIdProjectIdItemIds(user.getId(),projectId,projectItemIds);
      for(ScoreHistory item: hasScoreItemList) {
        hasScoreItemMap.put(item.getProjectItemId(),item);
      }
    }
    
    List<ProjectItems> allProjectItems = ProjectItemsHandler.getByProject(projectId);
    Map<Integer, String> allProjectItemMap = new HashMap<Integer,String>();
    Map<Integer, String> allProjectItemTreeMap = new HashMap<Integer,String>();
    for(ProjectItems p: allProjectItems) {
      allProjectItemMap.put(p.getScoreItem().getId(), "true");
      allProjectItemTreeMap.put(p.getScoreItem().getScoreTree().getId(), "true");
    }
    context.put("allProjectItemMap", allProjectItemMap);    
    context.put("allProjectItemTreeMap", allProjectItemTreeMap); 
    context.put("hasScoreItemSize", ScoreHistoryHandler.getByUserIdProjectId(user.getId(), projectId).size());
    context.put("hasScoreItemMap", hasScoreItemMap);
    context.put("itemList", projectItemsList);
    context.put("viewUser", user);
    context.put("tree", ScoreTreeHandler.loadById(treeId));    
    
    out.println(TemplateUtil.getOutput(context,"/view/judge/scoreProjectByPerson.html"));
%>
<%@include file="/pub/footer.jsp"%>